package com.quanyan.place.service.impl;

import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.constants.Constants;
import com.quanyan.place.client.ApiPlaceClient;
import com.quanyan.place.entity.apiresp.RespBizPlaceBaseInfo;
import com.quanyan.place.request.ReqCommentAdd;
import com.quanyan.place.request.ReqSearchVo;
import com.quanyan.place.response.RespPlaceMemberCardDetail;
import com.quanyan.place.service.ApiPlaceService;
import com.quanyan.place.wrapper.PlaceMemberWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhaohui on 2017/5/16.
 */
@Service("apiPlaceClient")
public class ApiPlaceClientServiceImpl implements ApiPlaceClient{
    @Autowired
    ApiPlaceService apiPlaceService;

    @Autowired
    PlaceMemberWrapper placeMemberWrapper;
    /**
     * 搜索场馆列表
     * @param reqSearchVo
     * @return
     */
    @Override
    public APIResponse<PageObj<List<RespBizPlaceBaseInfo>>> placeSearch(ReqSearchVo reqSearchVo) {

        if (StringUtils.isEmpty(reqSearchVo.getSearchType())){
            return APIResponse.returnFail("搜索失败");
        }
        if (StringUtils.isEmpty(reqSearchVo.getPageNum())){
            reqSearchVo.setPageNum(Constants.DEFAULT_PAGE_NUM);
        }
        com.quanyan.place.entity.apireq.ReqSearchVo reqSearchVo1 = new com.quanyan.place.entity.apireq.ReqSearchVo();
        BeanUtils.copyProperties(reqSearchVo,reqSearchVo1);
        return apiPlaceService.placeSearch(reqSearchVo1);
    }
    /**
     * 场馆会员
     * @param userId
     * @return
     */
    @Override
    public APIResponse<List<RespPlaceMemberCardDetail>> getMyVenueVipList(Integer userId) {
        if (!StringUtils.isEmpty(userId) && userId != 0) {
            List<com.quanyan.place.entity.apiresp.RespPlaceMemberCardDetail>  cardDetail =
                    (List<com.quanyan.place.entity.apiresp.RespPlaceMemberCardDetail>)
                    placeMemberWrapper.getMyVenueVipList(userId).getData();
            List<RespPlaceMemberCardDetail> respPlaceMemberCardDetail = new ArrayList<>();
            BeanUtils.copyProperties(cardDetail,respPlaceMemberCardDetail);
          return APIResponse.returnSuccess(respPlaceMemberCardDetail);
        }
        return APIResponse.returnFail("用户没有登录");
    }


    @Override
    public APIResponse<Integer> placeComment(ReqCommentAdd reqCommentAddNew) {
        try {
            APIResponse<Integer> apiResponse =  apiPlaceService.comment(reqCommentAddNew);
            return apiResponse;
        } catch (Exception e) {
            e.printStackTrace();
            return APIResponse.returnFail("");
        }

    }
}
